package com.blogSystem.article.util;

import com.sun.xml.internal.ws.spi.db.DatabindingException;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
public class UpLoadMore {

  public  List<String> upLoadFile(MultipartFile[] uploads, HttpServletRequest request) {

   // String filePath=request.getSession().getServletContext().getRealPath("/");

    String filePath="F:/blog_system/blog_system_web/src/main/resources/static/";
    List<String> list=new ArrayList<String>();

    for (MultipartFile upload : uploads) {
      String fileName = upload.getOriginalFilename();
      Date now=new Date();

      String salt = now.getTime()+"";
      String newFilePath = filePath + salt + fileName;
      String newFileName = salt + fileName;

      try {
        upload.transferTo(new File(newFilePath));
        list.add(newFileName);
      } catch (IOException e) {
        e.printStackTrace();
        return list;
      }
    }
    return list;
  }
}
